package drg_group.wuxi_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.wuxi_2022.Base;
import drg_group.wuxi_2022.MedicalRecord;
import drg_group.wuxi_2022.ADRG.*;

public class MDCR{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"D47.001","C49.901","C83.803","C91.008","C92.703","C94.202","C94.400x001","Z51.000x012","Z51.800x953","C92.100x019","C95.900x003+M36.1*","C82.500","C91.401","Z51.101","C46.300","C83.000","C92.100x012","C91.400x013","C92.100x016","C91.000x009","C85.900x008","C90.000x004","C88.000x002","Z51.001","C83.702","C83.801","D46.900x004","C95.000x116","D46.700x006","C85.900x039","D47.402","C92.005","Z51.805","C93.003","D48.722","C92.300x001","C96.700","C95.003","C93.101","C82.900","C90.100x002","C82.702","C79.829","C85.900x012","Z54.001","C97.x01","C83.306","D46.700x003","C77.503","Z51.800x096","C90.000x025","C85.900x027","C96.800","C92.007","C90.000x028","C94.001","C88.300","C79.800x816","C83.501","Z51.800x925","C90.000x005","D46.203","C85.900x024","C90.300","C92.200","Z51.003","C48.101","C85.900x017","C96.601","C96.900","D47.101","C79.811","C83.307","C90.000x008+M90.6*","C91.004","C92.100x011","C92.201","D09.700","Z51.000x008","C83.802","C46.900x002","C91.701","C92.300","C78.604","C77.300x001","C90.000x011","C92.100x004","C95.000x015","C81.300","C85.900x043","C92.706","Z09.100","C83.001","C95.002","D47.100x019","C91.000x014","C91.000x012","C92.000x013","C92.000x006","D36.711","C92.000","C92.102","C85.900x031","C84.400","C95.100x012","C96.202","C92.103","C85.707","D48.700x023","Z51.800x951","C94.700x014","C90.000x014","C95.700x003","D48.708","C76.700","Z51.800x952","C85.900x004","C85.715","C85.100x010","C92.000x012","C77.202","D36.700x023","D46.100","C92.400x011","C90.000x035","C46.900x004","D46.700x008","C80.902","C83.301","C95.900x012","C95.000x003","C92.000x011","C96.400x001","C77.301","C85.100x017","D48.901","C84.700","C77.200","C92.006","C96.004","C81.200","C91.700","C93.104","C85.900x036","D47.401","C83.002","C92.901","C93.700","C91.400x004","C85.900x020","C79.900x001","C94.300x011","Z51.800x095","C85.900x023","C86.500","Q85.909","C90.200x009","C79.800x837","C91.704","D36.700x012","C46.900x003","Z51.800x981","C83.900","C90.000x012","C91.300","C94.000x001","C82.903","C92.900","C94.700x004","C90.000x039","C95.004","C90.000x027","C95.000x016","C92.004","D36.705","C95.900","C91.400","C83.500","C90.200x013","C83.300x007","C95.100","C91.000x017","C85.900x037","D47.200","D47.200x005+G63.1*","C96.200x013","C82.703","D47.004","C80.001","C92.700x012","Z51.100x004","C84.405","C79.900","C88.700","C94.200","D45.x00","C90.300x003","C91.100","D46.900","C88.202","C85.900x003","C96.501","C92.000x018","C91.000x013","Z08.800x001","C91.003","D47.100x007","D36.700x025","C96.603","C91.001","D47.700x006","C90.000x040","D47.000","C91.000x015","D47.100x009","C90.302","C46.700","C92.300x013","C94.000x011","C83.700","D47.002","C95.000x101","C90.200","D47.100x008","C81.701","D47.900x002","C90.200x008","C45.100x005","C83.300x008","C79.800x804","C90.000x029","C83.003","Z08.100","Z08.700","C88.200","C92.100x014","D18.106","C95.901","D47.703","C77.502","Z51.808","C95.000x102","C92.501","D18.109","C92.600","C91.500","C77.300x003","C92.700x006","C77.300","C76.300","C82.704","C83.505","C77.206","C86.602","C92.200x011","C76.302","C95.000x018","Z51.200x008","C81.900","C94.300","C88.302","C86.300","C84.402","C84.407","C85.900x028","C88.700x003","C90.301","D47.900","Z51.800x921","D36.700x021","C96.402","C83.100","C91.000x016","C79.800x811","C88.900","C88.401","Z08.900","C90.000x026","Z51.500x002","C91.100x011","C83.800","D46.201x001","C90.000x032","C95.900x005","Z08.800x004","D46.901","C46.800","C93.103","C46.900","C85.900x038","C91.900","D47.003","C77.501","D46.100x002","C80.905","C48.102","C84.600","C85.100x021","C76.200x002","C93.100x013","C95.100x011","C97.x00","D48.715","C84.901","C79.800x818","D48.707","C85.900x029","C91.600","C88.203","C45.103","D36.700x028","D47.700","C77.900x001","D46.900x006","C92.002","C85.700","C90.303","C85.900x001","C80.904","C83.305","C84.406","C91.000x006","C92.100","C77.302","C92.200x001","C94.200x011","C91.002","D19.900x001","D09.900","C84.400x001","C95.000x118","D48.716","C85.701","C77.900","C84.601","C85.900x042","C77.500","C90.100x011","Z51.800x924","C81.703","C84.502","C91.101","C90.000x031","C91.102","C90.100","C76.800","C96.600","C80.901","C96.002","C96.201","C85.900x013","C96.400x002","C81.000","C95.700x011","C93.102","C83.504","C86.400","D47.400","C96.704","C90.000x034","D47.403","C90.002","C96.401","Z08.000","C91.500x011","D46.400","Z08.200","D47.100","C82.701","D36.700x016","Z51.807","C92.403","C82.000","C86.603","C83.004","C93.701","C85.900x034","C76.801","C86.601","C90.000x041","Z51.800x097","C91.100x012","C85.900x016","C96.705","D46.001","Z51.811","C85.900x015","C92.601","C93.300","D89.801","C88.900x001","C92.500x011","C90.000x023","C94.400","C84.500","Z51.800x927","D46.700","D46.500","C91.000x007","C88.201","Z51.800x922","D47.100x004","C85.100","Z51.809","C96.602","D47.702","C82.400","C90.000x038","C76.101","C91.901","D46.200","C94.600","C88.700x012","C83.303","C85.900x019","C85.901","C82.300","C96.400","C83.101","D46.700x001","C92.800","D48.723","D47.200x004+G63.1*","C92.700x013","D48.700x001","C88.301","C86.100","C92.101","C77.401","Z51.104","C92.900x011","C83.102","C83.304","Z51.500x003","Z51.002","Z51.500x001","C84.000","C95.006","D36.704","C82.700","Z51.000x003","C90.000x036","C95.000","C96.500","C92.300x003","C91.000","C85.900x011","Q85.802","D46.600","C84.500x016","C93.300x001","C82.600","C92.300x011","C93.001","D48.900","C92.100x018","C95.700x002","C88.402","C45.706","D46.100x012","Z51.810","D47.404","D47.700x005","C84.403","C90.001","C80.900","Z51.800x092","C93.100","Z08.800x002","C91.007","C85.900x005","Z51.806","C85.900","C84.000x002","C92.000x014","C83.800x006","D09.700x001","D47.100x017","C83.300x009","C84.401","C83.800x008","C96.403","C88.701","C85.704","C94.700","C78.605","C88.200x012","C92.008","Z51.103","C81.400","C96.200x005","C93.100x012","C95.000x017","C95.700x001","C96.000","C90.300x002","C96.801","C92.001","C88.700x013","C95.000x115","D47.500","D46.700x007","C77.400x001","D48.902","Z09.200","C85.900x030","D47.300","C81.702","D48.700x015","C83.703","C92.000x017","C92.701","C85.709","C88.000","Z51.000x013","C85.700x004","C95.900x015","C88.403","C84.404","C90.000x033","C83.502","C84.800","C90.000x022","C92.000x003","C82.901","D47.200x003","D48.725","Z08.800x003","C92.402","C83.302","C91.006","C93.900","C85.900x006","C92.700","Z51.102","C92.100x001","C92.502","C84.100","D47.900x001","C91.800","C92.000x016","C93.002","C85.900x041","C90.300x001","D36.700x011","C76.305","Z51.800x094","C85.705","C94.201","C81.100","C82.200","C88.000x012","C86.200","Z51.804","C94.004","C85.900x009","C88.000x011","C95.005","C92.003","C79.800x862","C86.000","D47.701","C93.100x011","C77.800","C90.300x004","C95.000x002","C94.702","C93.000x011","C96.200","C85.700x016","C85.900x002","C93.000x016","C92.900x001","C92.100x002","C81.700","Z51.802","C79.826","C84.900","C85.900x026","C81.900x005","C84.500x012","C92.000x015","C90.000x024","C85.900x040","C76.306","D47.100x018","C83.300x006","D18.105","C45.900","C88.400","C88.700x002","C93.901","C90.000x009","C85.900x014","C96.604","C84.500x004","C95.000x117","D19.700","C77.107","C85.900x022","C77.205","C86.600","C85.900x025","C96.502","D36.710","C77.303","D36.709","C85.200","C92.100x017","C96.400x004","C92.009","C90.000x037","C88.200x011","Z51.800x983","Z51.801","C90.000x021","D46.900x002","C80.903","C83.503","D47.700x007","C96.400x003","C80.000","C80.000x001","C90.000x030","C90.000","C92.401","C84.000x003","C94.703","C83.300","C95.900x013+M36.1*","D46.700x002","C82.100","C85.900x010","C76.700x002","C83.800x009"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCR入组条件，匹配规则：主诊断匹配");
        String result;

        result=RA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA3.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA4.group(record);
        if (result.length()>0){
            return result;
        }

        result=RB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RB2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RD1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RE1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RG1.group(record);
        if (result.length()>0){
            return result;
        }

        if (record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合RQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "RQY";
        }

        result=RR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RS2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RT1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RT2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RW1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RW2.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCR的ADRG入组条件");
        return "";
    }
}

